package org.sunrise.game.client.client;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import lombok.Data;

@Data
public class PlayerInfo {
    private String id;
    private String name;
    private Vector2 playerPos;   // 当前位置
    private Vector2 targetPos;   // 目标位置
    private Texture playerTexture; // 角色图片
    private SpriteBatch batch;

    public PlayerInfo(String id, float x, float y, String name) {
        this.id = id;
        this.name = name;
        this.playerPos = new Vector2(x, y);
        this.targetPos = new Vector2(x, y);
    }

    public void setTargetPosition(float x, float y) {
        this.targetPos.set(x, y);
    }

    public void updatePosition(float delta) {
        if (playerTexture == null) {
            playerTexture = new Texture(Gdx.files.internal("player.png"));
        }
        if (batch == null) {
            batch = new SpriteBatch();
        }
        batch.begin();
        batch.draw(playerTexture, playerPos.x, playerPos.y);

        playerPos.lerp(targetPos, 5f * delta); // 平滑移动
        batch.end();
    }
}
